package edu.sctu.practice.class02.hujie.cgs.assign02s;

import javax.swing.*;

/**
 * Created by hp on 2015/12/24.
 */
public class GuessNumber {
    public static void main(String[] args) {
        System.out.println("给你一个1至100之间的整数，请猜测这个数");
        int realNumber = (int) (Math.random() * 100) + 1;
        int youGuess = 0;
        String str = JOptionPane.showInputDialog("输入您的猜测：");
        youGuess = Integer.parseInt(str);
        while (youGuess != realNumber) {
            if (youGuess > realNumber) {
                str = JOptionPane.showInputDialog("猜大了，再输入您的猜测：");
                youGuess = Integer.parseInt(str);
            } else if (youGuess < realNumber) {
                str = JOptionPane.showInputDialog("猜小了，再输入您的猜测：");
                youGuess = Integer.parseInt(str);
            }
        }
        System.out.println("猜对了！");
    }
}
